package com.etoak.car.service;

import com.etoak.car.bean.Gift;
import com.etoak.car.bean.Order;
import com.etoak.car.bean.vo.GiftCountResp;
import com.etoak.car.bean.vo.GiftResp;
import com.etoak.car.mapper.GiftMapper;
import com.etoak.commons.page.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GiftService {

    @Autowired
    private GiftMapper giftMapper;

    public Page<Gift> querySome(int pageNum,int pageSize) {
        //设置分页条件
        PageHelper.startPage(pageNum,pageSize);
        //查询功能
        List<Gift> order = giftMapper.querySome();
        //创建pageInfo
        PageInfo<Gift> pageInfo = new PageInfo<>(order);

        //返回结果
        return new Page<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal(),
                order,
                pageInfo.getPages());
    }

    public int delGift(int id) {
        return giftMapper.delGift(id);
    }

    public int updateGift(Gift gift) {
        return giftMapper.updateGift(gift);
    }

    public Page<GiftResp> querySomeByUser(int pageNum,int pageSize) {
        //设置分页条件
        PageHelper.startPage(pageNum,pageSize);
        //查询功能
        List<GiftResp> order = giftMapper.querySomeByUser();
        //创建pageInfo
        PageInfo<GiftResp> pageInfo = new PageInfo<>(order);

        //返回结果
        return new Page<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal(),
                order,
                pageInfo.getPages());

    }

    public int addGift(Gift gift) {
        return giftMapper.addGift(gift);
    }

    public Gift getDataById(int id) {
        return giftMapper.getDataById(id);
    }

    public int delUserGift(int id) {
        return giftMapper.delUserGift(id);
    }

    public List<GiftCountResp> giftCountByUser() {
        return giftMapper.giftCountByUser();
    }


    public Page<Gift> getGiftByUser(int pageNum,int pageSize) {
        //设置分页条件
        PageHelper.startPage(pageNum,pageSize);
        //查询功能
        List<Gift> order = giftMapper.getGiftByUser();
        //创建pageInfo
        PageInfo<Gift> pageInfo = new PageInfo<>(order);

        //返回结果
        return new Page<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal(),
                order,
                pageInfo.getPages());

    }

    public int addGiftOrder(int userId, int giftId) {
        return giftMapper.addGiftOrder(userId,giftId);
    }

    public Gift getCountById(int giftId) {
        return giftMapper.getCountById(giftId);
    }

    public int delGiftCount(int giftId) {
        return giftMapper.delGiftCount(giftId);
    }

    public int getJiFenById(int userId) {
        return giftMapper.getJiFenById(userId);
    }

    public int delUserJiFen(int userId,double price) {
        return giftMapper.delUserJiFen(userId,price);
    }

    public Page<GiftResp> queryGiftOrderByUser(int userId,int pageNum,int pageSize) {
        //设置分页条件
        PageHelper.startPage(pageNum,pageSize);
        //查询功能
        List<GiftResp> order = giftMapper.queryGiftOrderByUser(userId);
        //创建pageInfo
        PageInfo<GiftResp> pageInfo = new PageInfo<>(order);

        //返回结果
        return new Page<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal(),
                order,
                pageInfo.getPages());

    }
}
